﻿function AzureOnlineBlobContainerDetailsView(context) {

    var self = this;
    
    var dispatcher = $({});
    var container = ko.observable(null);
    var screen = ko.observable('properties');

    var metadata = new AzureOnlineBlobContainerMetadataView(context);
    var properties = new AzureOnlineBlobContainerPropertiesView(context);
    
    function init(containerModel) {
        container(containerModel);
        metadata.init(containerModel);
        properties.init(containerModel);
    }

    metadata.addOnSuccess(onSuccess);
    properties.addOnSuccess(onSuccess);

    function submit() {
        switch (screen()) {
            case 'properties':
                properties.submit();
                break;
            case 'metadata':
                metadata.submit();
                break;
        }
    }
    
    function goToProperties() {
        screen('properties');
    }
    
    function goToMetadata() {
        screen('metadata');
    }
    
    function onSuccess() {
        dispatcher.trigger('success');
    }

    self.container = container;
    self.init = init;
    self.submit = submit;
    self.screen = screen;
    self.goToProperties = goToProperties;
    self.goToMetadata = goToMetadata;
  
    self.metadataView = metadata;
    self.properties = properties;

    this.addOnSuccess = function (handler) {
        dispatcher.bind('success', handler);
    };
}